/*
 * @Description:
 * @Author: fhw
 * @Date: 2022-07-18 10:30:37
 */
import { MiddlewareConsumer, Module, NestModule, RequestMethod } from '@nestjs/common'
import { TypeOrmModule } from '@nestjs/typeorm'
import { AdminController } from './admin.controller'
import { AdminService } from './admin.service'
import { ArticleModule } from './article/article.module'
import { LoggerMiddleware } from './logger.middleware'
import { ArticleCategoryModule } from './article_category/article_category.module'
import { ArticleTagModule } from './article_tag/article_tag.module'
import { ArticleCommentModule } from './article_comment/article_comment.module'
import { ChatUserGroupModule } from './chat_user_group/chat_user_group.module'
import { ChatUserFriendsModule } from './chat_user_friends/chat_user_friends.module'
import { ChatUserModule } from './chat_user/chat_user.module'
import { GroupChatModule } from './group-chat/group-chat.module'

/** .socket */
import { SocketMessageModule } from './socket/socket-message/socket-message.module'
import { SocketFriendChatModule } from './socket/socket-friend-chat/socket-friend-chat.module'
import { ConfigModule } from './socket/config/config.module'
import { SocketIndexModule } from './socket/socket-index/socket-index.module';
import { SocketRoomModule } from './socket/socket-room/socket-room.module';
import { SysMessageModule } from './sys_message/sys_message.module'
import { ResumeModule } from './resume/resume.module';


import { APP_GUARD } from '@nestjs/core';
import { ThrottlerModule, ThrottlerGuard } from '@nestjs/throttler';
import { MailModule } from './mail/mail.module'
import { MessageBoardModule } from './message-board/message-board.module';
import { ChatRecordModule } from './chat-record/chat-record.module';
import { EpidemicSituationModule } from './epidemic-situation/epidemic-situation.module';
import { UploadModule } from './upload/upload.module';
import { HistorySessionModule } from './history-session/history-session.module';
@Module({
  imports: [
    // 限度客户端在规定的时间内申请次数
    ThrottlerModule.forRoot({
      ttl: 60,  //1分钟
      limit: 60, //申请10次
    }),
    TypeOrmModule.forRoot({
      type: 'mysql',
      host: 'localhost',
      port: 3306,
      username: 'root',
      password: 'root',
      database: 'chat',
      synchronize: true,
      cache: true,
      autoLoadEntities: true,
    }),

    ArticleModule,
    ArticleCategoryModule,
    ArticleTagModule,
    ArticleCommentModule,
    // SocketTestModule,
    SocketMessageModule,
    GroupChatModule,
    ChatUserModule,
    ChatUserFriendsModule,
    ChatUserGroupModule,
    SysMessageModule,
    SocketFriendChatModule,
    ConfigModule,
    SocketIndexModule,
    SocketRoomModule,
    ResumeModule,
    MailModule,
    MessageBoardModule,
    ChatRecordModule,
    EpidemicSituationModule,
    UploadModule,
    HistorySessionModule,
  ],
  controllers: [AdminController],
  providers: [
    AdminService,
    {
      provide: APP_GUARD,
      useClass: ThrottlerGuard,
    },
  ],
})
export class AdminModule implements NestModule {
  configure(consumer: MiddlewareConsumer) {
    consumer.apply(LoggerMiddleware).forRoutes({ path: 'article', method: RequestMethod.GET })
  }
}
